#include <iostream>

using namespace std;

const int N = 105;
int n, m;
int g[N][N];

const int dir[8][2] = {{-1, 0},
                       {0,  1},
                       {1,  0},
                       {0,  -1},
                       {-1, -1},
                       {-1, 1},
                       {1,  -1},
                       {1,  1}};

int bfs(int x, int y) {
    int res = 0;
    for (int i = 0; i < 8; ++i) {
        int xx = x + dir[i][0], yy = y + dir[i][1];
        if (xx < 0 || xx >= n || yy < 0 || yy >= m) {
            continue;
        }
        if (g[xx][yy] == 1) {
            res++;
        }
    }
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    cin >> n >> m;

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            cin >> g[i][j];
        }
    }

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            if (g[i][j] == 1) {
                cout << 9 << " ";
            } else {
                cout << bfs(i, j) << " ";
            }
        }
        cout << endl;
    }

    return 0;
}